import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/welcome.vue'
import User from '../components/user/user.vue'
import Rigths from '../components/rigths.vue'
import Rolse from '../components/roles.vue'
import Cate from '../components/goods/cate.vue'
import Params from '../components/goods/params.vue'
import Goods from '../components/goods/goods.vue'
import App from '../components/goods/App.vue'
import Order from '../components/order/order.vue'
import Reports from '../components/order/Report.vue'


Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    { path: '/home', component: Home ,redirece:'/welcome',
    children:
    [
    { path:'/welcome',component:Welcome},
    {path:'/users',component:User},
    {path:'/rights',component:Rigths},
    {path:'/roles',component:Rolse},
    {path:'/categories', component:Cate},
    {path:'/params',component:Params},
    {path:'/goods',component:Goods},
    {path:'/goods/app',component:App},
    {path:'/orders',component:Order},
    {path:'/reports',component:Reports}




    ]}
  ]
})
//  挂载路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const toankStr = window.sessionStorage.getItem('token')
  if (!toankStr) { return next('/login') }
  next()
})


export default router
